<?php 
$lang="VN";
$company="elitech";
//$username="abc";
//$status=1;
//$lang=$_REQUEST['lang'];
//$company=$_REQUEST['company'];
//$username=$_REQUEST['username'];
//$status=$_REQUEST['status'];

/*$lang=$_REQUEST['lang'];
$company=$_REQUEST['company'];
$username=$_REQUEST['username'];
if(isset($_REQUEST['status']))
	$status=$_REQUEST['status'];
else
	$status=1;

if($status==0){
	$l_thoigiangiaodich=$l_thoigiangiaodich0;
}
if($status==1){
	$l_thoigiangiaodich=$l_thoigiangiaodich1;
}*/


$status=1;


$connection = mysql_connect("1.234.53.52", "cam", "5678" ) ;
//$connection = mysql_connect("localhost", "root", "root" ) ;
mysql_select_db("elihan", $connection);
mysql_query("set names 'utf8'");
$selectdatabase = mysql_query("SELECT am.DatabaseName,am.Logo from ac_eli_manager am where am.KeyName='$company' and am.`Status` = 2");
$result = mysql_fetch_assoc($selectdatabase);
$db= $result['DatabaseName'];
//echo $db;
mysql_select_db($db, $connection);


if (empty($lang) || $lang == "EN") {
	$value = "value/value_en.php";
} else if($lang == "VN") {
	$value = "value/value_vn.php";
}else {
	$value = "value/value_kr.php";
}
include($value);

$result=mysql_query("select * from manage_money");

$logmoney0=mysql_query("SELECT * FROM or_order_tax o WHERE o.is_status=0 ORDER BY o.order_time DESC LIMIT 0,10;");
$logmoney1=mysql_query("SELECT * FROM or_order_tax o WHERE o.is_status=1 ORDER BY o.order_time DESC LIMIT 0,10;");
// file 03-gmail.php
		
		//NhÃƒÂºng thÃ†Â° viÃ¡Â»â€¡n phpmailer
		require_once('class.phpmailer.php');
		
		//KhÃ¡Â»Å¸i tÃ¡ÂºÂ¡o Ã„â€˜Ã¡Â»â€˜i tÃ†Â°Ã¡Â»Â£ng
		$mail = new PHPMailer();
		
		$mail->IsSMTP(); // GÃ¡Â»ï¿½i Ã„â€˜Ã¡ÂºÂ¿n class xÃ¡Â»Â­ lÃƒÂ½ SMTP
		//$mail->Host       = "mail.zend.vn"; // tÃƒÂªn SMTP server
		$mail->SMTPDebug  = 2;                    // enables SMTP debug information (for testing)
		                                           // 1 = errors and messages
		                                           // 2 = messages only
		$mail->SMTPAuth   = true;                  // SÃ¡Â»Â­ dÃ¡Â»Â¥ng Ã„â€˜Ã„Æ’ng nhÃ¡ÂºÂ­p vÃƒÂ o account
		$mail->SMTPSecure = "ssl";
		$mail->Host       = "smtp.gmail.com";     // ThiÃ¡ÂºÂ¿t lÃ¡ÂºÂ­p thÃƒÂ´ng tin cÃ¡Â»Â§a SMPT
		$mail->Port       = 465;                     // ThiÃ¡ÂºÂ¿t lÃ¡ÂºÂ­p cÃ¡Â»â€¢ng gÃ¡Â»Â­i email cÃ¡Â»Â§a mÃƒÂ¡y
		$mail->Username   = "elisoftmailserver@gmail.com"; // SMTP account username
		$mail->Password   = "1234567892727";         // SMTP account password
		
		//Thiet lap thong tin nguoi gui va email nguoi gui
		//$yesterday=date("Y-m-d", time() - 86400);
		$mail->SetFrom('elisoftmailserver@gmail.com',$company.' - '.$l_money1);
		
		//ThiÃ¡ÂºÂ¿t lÃ¡ÂºÂ­p thÃƒÂ´ng tin ngÃ†Â°Ã¡Â»ï¿½i nhÃ¡ÂºÂ­n
		//$mail->AddAddress("klkim169@gmail.com", "klkim");
		//$mail->AddAddress("luanfantasy@gmail.com", "Nguyễn Trương Thành Luân");
		//$mail->AddAddress("kisadlu@gmail.com", "Nguyễn Thị Kim Sang");
		//$mail->AddAddress("vinhelisoftvietnam@gmail.com", "Lê Quang Vinh");
		$mail->AddAddress("orchipro@gmail.com", "orchipro");
		
		$mail->Subject    =  $company.' - '.$l_money1;
		
		$mail->CharSet = "utf-8";
		$mail->IsHTML(true);
	
		
		$body='';
		$body.='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml">
				<head>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
				<title>Untitled Document</title>
				</head>
				
				<body>
				<table style="width:100%; padding-left:10px;">';
							
								while ($row = mysql_fetch_array($result)){
							
							$body.='<tr >
								<td  style="background: rgb(92, 165, 206);padding: 5px;width: 180px;">'.$row['name'.$lang].'</td>
								<td style="width: 260px"><input type="text" id="txttime" name="txttime" value="'.number_format($row['value']).'" style="width:185px;float:left;height:36px;text-align: right;border: 1px solid #ccc;font-size: 9pt;color: #555;line-height: 20px;" readonly="readonly"/>  <p style="padding-left: 200px;">  VNĐ</p></td>
								<td></td>
							</tr>';
							 }
							
						$body.='</table>
				</body>
				</html>';

$body.='<br><b style="padding-left: 10px;">'.$l_Invoice_thu.'</b>';

$body.='<br><table cellpadding="0" cellspacing="1" border="0" class="ftable1" style="width: 100%;padding-left: 10px">
				            <tbody>
				            <tr height="30px">
				                <th style="width: 30px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_no.'</th>
				                <th style="width: 200px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_ngaythangnam.'</th>
				                <th style="min-width: 160px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_company_name.'</th>
				                <th style="min-width: 180px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_product_item.'</th>
				                <th style="width: 150px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_Supply_price.'</th>
				                <th style="width: 150px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_vat.'</th>
				                <th style="width: 150px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_amount.'</th>
				                <th style="width: 200px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_thoigiangiaodich0.'</th>
				                <th style="min-width: 150px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_memo.'</th>
				            </tr>';
$i=1;
while ($r = mysql_fetch_array($logmoney0)){
	if($r['order_time_transaction']=="0000-00-00")
		$order_time_transaction="";
	if ($r['status']==1)
		$order_time_transaction="-";
				            $body.='<tr style="background:#d0d8e8;height : 30px" height="30px">
				                <td style="text-align: center;height : 30px">'.$i.'</td>
				                <td style="text-align: center;height : 30px">'.$r['order_time'].'</td>
				                <td style="text-align: left;padding-left: 5px;height : 30px">'.$r['order_cusname'].'</td>
				                <td style="text-align: left;padding-left: 5px;height : 30px">'.$r['order_content'].' VNĐ </td>
				                <td style="text-align: right;padding-right: 5px;height : 30px">'.number_format($r['order_supply_rice']).'</td>
				                <td style="text-align: right;padding-right: 5px;height : 30px">'.number_format($r['order_tax']).'</td>
				                <td style="text-align: right;padding-right: 5px;height : 30px">'.number_format($r['order_total']).'</td>
				                <td style="text-align: center;height : 30px">'.$order_time_transaction.'</td>
				                <td style="text-align: center;height : 30px">'.$r['order_memo'].'</td>
				            </tr>';
				            $i++;
}
$body.=' </tbody></table>';
	
$body .='<br>';						

$body.='<br><b style="padding-left: 10px;">'.$l_Invoice_chi.'</b>';

$body.='<br><table cellpadding="0" cellspacing="1" border="0" class="ftable1" style="width: 100%;padding-left: 10px">
				            <tbody>
				            <tr height="30px">
				                <th style="width: 30px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_no.'</th>
				                <th style="width: 200px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_ngaythangnam.'</th>
				                <th style="min-width: 160px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_company_name.'</th>
				                <th style="min-width: 180px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_product_item.'</th>
				                <th style="width: 150px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_Supply_price.'</th>
				                <th style="width: 150px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_vat.'</th>
				                <th style="width: 150px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_amount.'</th>
				                <th style="width: 200px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_thoigiangiaodich1.'</th>
				                <th style="min-width: 150px;background: rgb(92, 165, 206);color: white;font-weight: bold;height : 30px">'.$l_memo.'</th>
				            </tr>';
$i=1;
while ($r = mysql_fetch_array($logmoney1)){
	if($r['order_time_transaction']=="0000-00-00")
		$order_time_transaction="";
	if ($r['status']==1)
		$order_time_transaction="-";
				            $body.='<tr style="background:#d0d8e8;height : 30px" height="30px">
				                <td style="text-align: center;height : 30px">'.$i.'</td>
				                <td style="text-align: center;height : 30px">'.$r['order_time'].'</td>
				                <td style="text-align: left;padding-left: 5px;height : 30px">'.$r['order_cusname'].'</td>
				                <td style="text-align: left;padding-left: 5px;height : 30px">'.$r['order_content'].' VNĐ </td>
				                <td style="text-align: right;padding-right: 5px;height : 30px">'.number_format($r['order_supply_rice']).'</td>
				                <td style="text-align: right;padding-right: 5px;height : 30px">'.number_format($r['order_tax']).'</td>
				                <td style="text-align: right;padding-right: 5px;height : 30px">'.number_format($r['order_total']).'</td>
				                <td style="text-align: center;height : 30px">'.$order_time_transaction.'</td>
				                <td style="text-align: center;height : 30px">'.$r['order_memo'].'</td>
				            </tr>';
				            $i++;
}
$body.=' </tbody></table>';
	
$body .='<br><table width="100%" style="padding:20px" >
	<tr><td align="right"><b>'.$l_sender.':</b> <b><i>'.$username.'</i></b></td></tr>
	</table>';
//echo $body;
$mail->Body = $body;
	
if(!$mail->Send()) {
  	echo "Mailer Error: " . $mail->ErrorInfo;
} else {
 	echo "Sent Money Successfully ";
}
mysql_close($connection);?>